package org.je.util;

/**
 * @author fanyifeng 2012-9-1 上午11:00:07
 */
public class CharUtil
{
	/***
	 * 忽略大小写对比
	 * 
	 * @param c1
	 * @param c2
	 */
	public static boolean equalsIgnoreCase(char c1, char c2) {
		if (c1 == c2)
			return true;

		int n = c1 > c2 ? c1 - c2 : c2 - c1;

		if (n != 32)
			return false;

		return isLetter(c1) && isLetter(c2);
	}

	/**
	 * 判断c是否在arr中
	 * 
	 * @param c
	 * @param array
	 * @return 是否
	 */
	public static boolean isInArray(char c, char[] array) {
		for (char i : array) {
			if (i == c)
				return true;
		}

		return false;
	}

	public static boolean isNameStartChar(char c) {
		return isLetter(c) || isZhChar(c) || c == '_';
	}

	public static boolean isNameChar(char c) {
		return isNameStartChar(c) || isNum(c);
	}

	/***
	 * 判断是否为中文字
	 * 
	 * @param c
	 * @return boolean
	 */
	public static boolean isZhChar(char c) {
		return c >= 0x4e00 && c <= 0x9fa5;
	}

	/**
	 * 是否为大写字母
	 * 
	 * @param c
	 * @return boolean
	 */
	public static boolean isBigLetter(char c) {
		return c >= 'A' && c <= 'Z';
	}

	/**
	 * 是否为小写字母
	 * 
	 * @param c
	 * @return boolean
	 */
	public static boolean isSmallLetter(char c) {
		return c >= 'a' && c <= 'z';
	}

	/**
	 * 是否为字母
	 * 
	 * @param c
	 * @return boolean
	 */
	public static boolean isLetter(char c) {
		return isBigLetter(c) || isSmallLetter(c);
	}

	/**
	 * 是否为空白字符
	 * 
	 * @param c
	 * @return boolean
	 */
	public static boolean isBlank(char c) {
		return c <= 32 || c == 12288 || c == 65279;
	}

	/**
	 * 是否为空白字符
	 * 
	 * @param c
	 * @return boolean
	 */
	public static boolean isNum(char c) {
		return c >= '0' && c <= '9';
	}
}
